package com.game.logic.fighting.actor;

import com.coment.cfg.luban.RolesSkillCfg;
import com.coment.game.fight.Attrs;
import com.coment.message.BuffInfo;
import com.coment.message.HurtInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/// 技能信息
@Data
@ToString
@AllArgsConstructor
public class SkillInfo {
    /// 主播id
    private final int anchorInfoId;

    /// 技能id
    private final int skillId;

    /// 释放技能的玩家id
    private Integer userInfoId;

    /// 释放技能角色id
    private String rolesId;

    /// 施法者施法技能时属性
    private final Attrs spellcasterPanelProperties;

    /// 目标角色id
    @JsonIgnore
    private String[] effectOnTheEnemy;

    @JsonIgnore
    private String[] effectOnFriendly;

    /// 是否触发
    public boolean trigger;

    /// 触发的buff信息
    public BuffInfo beforeBuff;

    /// 技能伤害信息
    public final List<HurtInfo> hurts;

    /// 技能配置
    @JsonIgnore
    private RolesSkillCfg cfg;

    public SkillInfo(int anchorInfoId, String rolesId, int skillId, String[] effectOnTheEnemy, String[] effectOnFriendly) {
        this.anchorInfoId = anchorInfoId;
        this.rolesId = rolesId;
        this.skillId = skillId;
        this.effectOnTheEnemy = effectOnTheEnemy;
        this.effectOnFriendly = effectOnFriendly;
        this.hurts =Collections.synchronizedList(new ArrayList<>());
        this.spellcasterPanelProperties = new Attrs();
    }

    public SkillInfo(Integer anchorInfoId, Integer userInfoId, int skillId) {
        this.anchorInfoId = anchorInfoId;
        this.userInfoId = userInfoId;
        this.skillId = skillId;
        this.hurts = Collections.synchronizedList(new ArrayList<>());
        this.spellcasterPanelProperties = new Attrs();
    }

    /// 技能伤害是否暴击
    @JsonIgnore
    public boolean isCrit() {
        if (hurts == null || hurts.isEmpty()) {
            return false;
        }
        return hurts.stream().anyMatch(hurt -> hurt.crit);
    }
}
